package com.tlvip.nkw;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>description：</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 2022/1/11</p>
 * Author mac
 *
 * @version 1.0
 */
public class Solution {

    public static void main(String[] args) {
        int[] num = new int[]{9, 10, 9, -7, -3, 8, 2, -6};
        int size = 5;
        List<Integer> result = maxInWindows(num, size);
        result.stream().forEach(System.out::println);
    }

    public static List<Integer> maxInWindows(int[] num, int size) {
        List<Integer> resultList = new ArrayList();
        if (num.length == 0 || size > num.length || size == 0) {
            return resultList;
        }
        for (int i = 0; i < num.length - size + 1; i++) {
            resultList.add(getMax(num, i, i + size));
        }
        return resultList;
    }

    private static int getMax(int[] subArray, int start, int end) {
        int max = subArray[start];
        for (int i = start + 1; i < end; i++) {
            if (max < subArray[i]) {
                max = subArray[i];
            }
        }
        return max;
    }
}
